<?php
namespace app\admin\controller;
use app\admin\model\Configs as ConfigsModel;

class Configs extends Backend {

    /**
     * 设置系统配置
     * @return mixed
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     * Author: LCY<409028735@qq.com>
     * Time: 2021/4/22 13:13
     * Note:
     */
    public function edit()
    {
        if($this->request->isPost()){

            //获取提交的数据
            $datas = input('post.');

            //验证数据
            $this->validate_response($datas, 'Configs');

            $configs = ConfigsModel::get(1);

            //保存数据
            if(false !== $configs->save($datas)){
                //清除缓存
                cache('configs', null);
                $this->writeAdminLog('系统设置');
                $this->success('设置完成');
            }else{
                $this->error('设置失败，请重试！');
            }

        }else{
            $this->assign('cash_types',config('extra.cash_types'));
            $this->assign('cash_dates',config('extra.cash_dates'));
            $this->assign('info', get_system_config());
            return $this->fetch();
        }
    }

}